<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%> 
<html>
<head>  
  <script type="text/javascript">
  function doSearch() {	 
	  grid.load({
			ins_cd: $('#ins_cd').val(),
			ins_cn_nm: $('#ins_cn_nm').val(),
			ins_type: $('#ins_type').val(),
			areaname: $('#areaname').val(),
			contact_person: $('#contact_person').val(),
			phone: $('#phone').val(),
			ins_st: $('#ins_st').val()			
		});
  }
  
  function addIns(url){
	  commonDetail(url,"save","insTableId");
  }
  function modifyIns(url){
	  var result = checkIsChangeCurrentUserIns();
	  if(!result){
		  return;
	  }
	  commonDetail(url,"update","insTableId");
  }
  function deleteIns(url){	  
	  var result = checkIsChangeCurrentUserIns();
	  if(!result){
		  return;
	  }
	  commonDel(url,"delete","insTableId");
  }
  function enableIns(url){
	  startOrStop(url, "确定启用吗");	  
  }
  function disabledIns(url){
	  startOrStop(url, "确定停用吗");	  
  }
  function getInsTree(url){
	  showInsTree(null, null, {buttons: null});
  }
  var grid;
  $(document).ready(function() {
	  grid = $("#insTableId").jpgrid({
			url: "getInsInfListJson.do",
			columns: [
				{title: "机构代码", field: "INS_CD",width: 80},				
				{title: "机构名称", field: "INS_CN_NM"},				
				{title: "机构类别", field: "INSTYPE",width: 140},
				{title: "机构所属地区", field: "AREANAME",width: 130},
				{title: "联系人", field: "CONTACT_PERSON",width: 80},
				{title: "联系电话", field: "PHONE",width: 120},
				{title: "上级机构", field: "SUBINSNAME"},
				{title: "机构状态", field: "INSST",width: 80}
			]
		});	
  });
  
  /**
  *	在新增修改删除启用停用之前检查是否是操作当前用户的所属的机构
  */
  function checkIsChangeCurrentUserIns(){
	  var isExist = false;
	  var checkedItems = checkSelected("insTableId", false);
	  if(!checkedItems){
		  return false;
	  }
	  var ids = "";
	  for(var i = 0 ; i < checkedItems.length; i++){
		  ids = ids + "," + (checkedItems[i]).UUID;
	  }
	  ids = replaceFirst(ids);
	  $.jpajax({
			url: "checkIsChangeCurrentUserIns.do",
			data: {ins_uuids : ids},
			success: function(result){
				if(result == "0"){ //没有勾选当前的机构的记录
					isExist = true;
				}else if(result == "1"){ //有勾选当前的机构的记录
					isExist = false;
					$.jpmessage.warning("不能够对用户当前所处的机构进行操作！");
				}
			}
	  });
	  return isExist;
  }
  
  /*启用或停用机构*/
  function startOrStop(url, msg){
	  var result = checkIsChangeCurrentUserIns();
	  if(!result){
		  return;
	  }
	  commonAsync(url, "insTableId", msg, function(data){
		  grid.reload();
	  });
  }
  </script>
</head>
<body class="easyui-layout list_body">
<form id="insForm" name="insForm" >
	<div class="list_body_north" data-options="region:'north'" border="false">
	 	<!-- 查询表单 -->
	 	<div  class="datagrid-toolbar" border="false"  >
			<div>
				<span>机构代码:</span>
				<input id="ins_cd" type="text" name="ins_cd"  class="easyui-textbox"  >
				<span>机构名称:</span>
				<input id="ins_cn_nm" type="text" name="ins_cn_nm"  class="easyui-textbox"  >	
				<span>机构类别:</span>
				<code:codeSelect id="ins_type" name="ins_type" code_type="ins_type" showSelect="true" selectId="${appInsInfEntity.ins_type}"></code:codeSelect>	
				<span>机构所属地区:</span>
				<input id="areaname" type="text" name="areaname"  class="easyui-textbox" />
			</div>
			<div>
				<span>联系人:</span>
				<input id="contact_person" type="text" name="contact_person"  class="easyui-textbox"  >	
				<span>联系电话:</span>
				<input id="phone" type="text" name="phone"  class="easyui-textbox"  > 
				<span>机构状态:</span>
				<code:codeSelect id="ins_st" name="ins_st" code_type="ins_st" showSelect="true" selectId="${appInsInfEntity.ins_st}"></code:codeSelect>		
			 	<a href="#" class="easyui-linkbutton btn" iconCls="icon-search" onclick="doSearch() ">查询</a>
			 	<a href="#" class="easyui-linkbutton btn" iconCls="icon-reload" onclick="resetForm() ">重置</a>
			</div>	 
		</div>
		<!-- 自定义标签工具栏 -->
		<jiepos:buttonOperateTag menuCode="${menuCode}"></jiepos:buttonOperateTag>
	</div>
	<div data-options="region:'center'" border="false" class="list_body_center">
		<!-- 表格 -->
	    <table id="insTableId" fit="true"></table>
    </div>
</form> 
</body>
</html>